<template>
  <div class="dynamic_from_icons" >
    <div class="icons_wrap" :style="style">
      <span v-for="(item, index) in props.question.handle" :key="index">
          <a-button  :type="item.type || 'primary'" v-permission="item.state.key" :class="item.class" @click="iconSubmit(item)">
            <!-- <plus-outlined /> -->
            <i class="iconfont" :class="item.class"></i>
            {{ item.value }}
          </a-button>
        </span>
    </div>
  </div>
</template>
<script setup lang="ts">
import { DYNAMICLAYERFORM, DYNAMICLAYERTABLE, DYNAMICLOCALICONS } from "@/mixins/subject/subject-types";
import { watch,getCurrentInstance,onMounted,onUnmounted, computed} from "vue";
import { QuestionBase } from "../../../question-base";
//subject变量

const { proxy  }:any = getCurrentInstance()
let props = defineProps<{ question: QuestionBase<any>, formData:any, formItemLayout:any}>();

onMounted(() => {

})

let style = computed(()=>{
let obj = {};
if( props.question.state && props.question.state.style ){
  obj = props.question.state.style;
}
return obj
})

//icon按钮
const iconSubmit = (item: any) => {
switch (item.key) {
  case 'router':
    proxy.$goTo(item.state.url, item.state.params);
    break;
  case 'local': //本地
    proxy.$NotificationPubSub.pushParams({ key: DYNAMICLOCALICONS, value: item, state: { formData: props.formData } });
    if (item.state.url) {
      proxy.$goTo(item.state.url, item.state.params);
    }
    break;
  case 'layerTable': //弹层table
    proxy.$NotificationPubSub.pushParams({
      key: DYNAMICLAYERTABLE,
      value: {
        tables: item.state.table,
        form: item.state.form,
        config: item.state.config,
        index: item.state.index || 0,
        name: item.state.name || ''
      }
    });
    break;
  case 'layerFrom': //弹层from
    proxy.$NotificationPubSub.pushParams({
      key: DYNAMICLAYERFORM,
      value: {
        config: item.state.config,
        form: item.state.form
      }
    });
    break;
}
};


</script>


<style lang="less" scoped>
@import url('./input-icons.component.less');
</style>
